package com.petrooil.core.dao;

import com.petrooil.core.model.UserDepartment;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.io.Serializable;

@Repository("userDepartmentDao")
public class UserDepartmentImpl implements CrudDao<UserDepartment> {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public UserDepartment create(UserDepartment userDepartment) {
        sessionFactory.getCurrentSession().persist(userDepartment);
        return userDepartment;
    }

    @Override
    public UserDepartment get(Serializable id) {
        return (UserDepartment) sessionFactory.getCurrentSession().get(UserDepartment.class, id);
    }

    @Override
    public UserDepartment update(UserDepartment userDepartment) {
        sessionFactory.getCurrentSession().update(userDepartment);
        return userDepartment;
    }

    @Override
    public void delete(UserDepartment userDepartment) {
        sessionFactory.getCurrentSession().delete(userDepartment);
    }

}
